﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;

namespace @catch
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          
        }

        private void button1_Click(object sender, EventArgs e)
        {
         
            string str = s;////shop/images_shop/21860/2011-09-08/10902011991926201212231.jpg
            Regex imgReg = new Regex("/shop/images_shop/[0-9]{3,6}/[0-9-]{10}/[0-9_DT]{20,29}.jpg");
            MatchCollection m = imgReg.Matches(str);
            string path;
            string url;
            WebClient client = new WebClient();
            if (m.Count == 0)
            {
                MessageBox.Show("没有");
                return;
            }
            for (int i = 0; i < m.Count; i++)
            {
                path = m[i].Value;
                url = "http://www.yaotiaoys.com" + path;
                path = "d:" + path;
               string dic= Path.GetDirectoryName(path);
               if (!Directory.Exists(dic))
               {
                   Directory.CreateDirectory(dic);
               }
                client.DownloadFile(url, path);
            }
        }
        string s;
        private void button2_Click(object sender, EventArgs e)
        {
            if (url.Text.Trim() == "")
            {
                MessageBox.Show("为空");
                return;
            }
            WebClient wc = new WebClient();
            Byte[] pageData = wc.DownloadData(url.Text.Trim());
             s = System.Text.Encoding.Default.GetString(pageData);
            //StreamWriter sw = new StreamWriter("tmp.txt");
            string titleStart = "<span id=\"Product_main1_Product_top21_Label1\">";
            string titleEnd = "</span>";
            int start = s.IndexOf(titleStart) + titleStart.Length;//标题开始
            int end = s.IndexOf(titleEnd, start);//标题结束
            title.Text = s.Substring(start, end - start);

            string numStart = "<span id=\"Product_main1_Product_top21_Label12\">";
            string numEnd = "</span>";
            start = s.IndexOf(numStart) + numStart.Length;
            end = s.IndexOf(numEnd, start);
            num.Text = "yaotiaoys-" + s.Substring(start, end - start);

            string startStr = "<span id=\"Product_main1_Product_top21_Label4\">";
            string endStr = "</span>";
            start = s.IndexOf(startStr) + startStr.Length;
            end = s.IndexOf(endStr, start);
            shichang.Text = s.Substring(start, end - start);//市场价
            xiaoshou.Text = (Math.Ceiling(Int32.Parse(shichang.Text) * 0.8)).ToString();
            kucun.Text = "100";
            zhongliang.Text = "1000";
            jinhuo.Text = (Math.Ceiling(Int32.Parse(shichang.Text) * 0.6)).ToString();

            //startStr = "<table class=\"ke-zeroborder\"";
            //endStr = "</table>";
            //start = s.IndexOf(startStr);
            //end = s.IndexOf(endStr, start);
            //miaoshu.Text = s.Substring(start, end - start) + endStr;

            startStr = "<table width=\"100%\" border=\"0\" cellpadding=\"12\" cellspacing=\"0\" class=\"SPSX_hang2\">";
            endStr = "</table>";
            start = s.IndexOf(startStr, end);
            end = s.IndexOf(endStr, start);
            string tmp1 = s.Substring(start, end - start) + endStr;

            miaoshu.Text += tmp1;
            //bool mutil=true;
            //start = 0;
            //while (mutil)
            //{
            //    startStr = "<td width=\"60%\" class=\"q88_1_STYLE11\" align =left >";
            //    endStr = "<input";
            //    start = s.IndexOf(startStr,start)+startStr.Length;

            //    if (start <= 0)
            //        mutil = false;
            //    end = s.IndexOf(endStr, start);
            //    guige.Text += s.Substring(start, end - start);
            //}

        }

        private void button3_Click(object sender, EventArgs e)
        {
            StreamReader sr = new StreamReader(@"D:\demo.csv",Encoding.Default);
            string demo = sr.ReadToEnd();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            Clipboard.SetText(title.Text);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            Clipboard.SetText(num.Text);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            Clipboard.SetText(xiaoshou.Text);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            Clipboard.SetText(shichang.Text);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            Clipboard.SetText(kucun.Text);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            Clipboard.SetText(zhongliang.Text);
        }

        private void button11_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            Clipboard.SetText(jinhuo.Text);
        }

        private void button12_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            Clipboard.SetText(miaoshu.Text);
        }

        private void button13_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            Clipboard.SetText(textBox9.Text);
        }

        private void button14_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            Clipboard.SetText(textBox10.Text);
        }
    }
}
